import { createBehavior, createResource } from '@inbiz/core';
import { ButtonGroup as LocaleButtonGroup } from './locale';
import {
  createInbizSchema,
  createComponentStyleSchema,
  createDecoratorStyleSchema,
  getDefalutDecoratorProps,
  createBaseSchema,
  createControllerSchema
} from '@inbiz/setters';
import Config from './config';
import { getPlatform } from '@inbiz/utils';

const defaultProps = {
  iconPosition: 'right',
  icon: {
    type: 'icon-ic-arrow-down-bold',
  },
  config: {
    subwindow: {
      width: '60%',
      height: '60%',
    },
    operation: {
      showType: 1,
    },
  },
};

export const Schema = {
  droppable: false,
  propsSchema: createInbizSchema({
    attribute: {
      ...createBaseSchema(
        {
          config: {
            type: 'object',
            'x-decorator': 'FormItem',
            'x-component': Config,
          },
        },
        undefined,
        true,
      ),
    },
    style: {
      ...createComponentStyleSchema({
        icon: {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': 'IconPicker',
          'x-component-props': {
            showIconSize: false,
            showColorPicker: false,
          },
        },
        iconPosition: {
          'x-decorator': 'FormItem',
          'x-component': 'Select',
          enum: ['left', 'right'],
        },
      }),
      ...createDecoratorStyleSchema(),
    },
    controller: createControllerSchema({
      events: [{
        name:'onClick',
        label:'点击',
        platform:'web'
      },
      {
        name:'onOpenChange',
        label:'下拉面板开关',
        platform:'web'
      },
      {
        name:'onPageInit',
        label:'子窗体初始化',
        platform:'web'
      },
      {
        name:'onPageMount',
        label:'子窗体挂载',
        platform:'web'
      },
      {
        name:'onAdd',
        label:'子窗体新增',
        platform:'web'
      },
      {
        name:'onEdit',
        label:'子窗体编辑',
        platform:'web'
      },
      {
        name:'onOpen',
        label:'子窗体打开',
        platform:'web'
      },
      {
        name:'onClose',
        label:'子窗体关闭',
        platform:'web'
      },
      {
        name: 'onCreateModel',
        label: '修改/创建弹窗数据',
        isConfigEvent: true,
        platform:'web'
      },
      {
        name: 'onBeforeOpen',
        label: '弹窗打开前事件',
        isConfigEvent: true,
        platform:'web'
      },
      {
        name: 'onBeforeClose',
        label: '弹窗关闭前事件',
        isConfigEvent: true,
        platform:'web'
      },
      {
        name: 'onBeforeOperationAsync',
        label: '保存前拦截事件',
        isConfigEvent: true,
        platform:'web'
      }
    ]
    })
  }),
};

export const Behavior = createBehavior({
  extends: ['Field'],
  name: 'EformButtonGroup',
  selector: (node) => node.props?.['x-component'] === 'EformButtonGroup',
  designerLocales: LocaleButtonGroup,
  designerProps: Schema,
});

export const Resource = createResource({
  icon: 'ButtonGroup',
  elements: [
    {
      componentName: 'Field',
      props: {
        title: {
          status: true,
          value: 'EformButtonGroup.title',
        },
        type: 'void',
        'x-decorator': 'Container',
        'x-component': 'EformButtonGroup',
        'x-component-props': defaultProps,
        'x-decorator-props': getDefalutDecoratorProps(getPlatform(), { border: false }),
      },
    },
  ],
});
